<template>
  <!-- <nav>
    <router-link to="/">Home</router-link> |
    <router-link to="/about">About</router-link> |
    <router-link to="/read">Read</router-link>
  </nav> -->
  <router-view />
</template>

<script>
import { mapState, mapMutations } from "vuex";
import { updateRoute } from "./utils";
import { getTimeRange } from "@/api";
import { SET_TIME_RANGE } from "@/store/mutation-types";

export default {
  name: "App",
  beforeMount() {
    getTimeRange()
      .then(({ data }) => {
        if (data.code === 0) {
          this.setTimeRange(data.content);
        } else {
          this.$message({ type: "error", message: data.msg });
        }
      })
      .then(() => {
        updateRoute(
          this.READING_TIME,
          this.START_ANSWER_TIME,
          this.END_ANSWER_TIME
        );
      });
  },
  methods: {
    ...mapMutations({
      setTimeRange: SET_TIME_RANGE,
    }),
  },
  computed: {
    ...mapState(["READING_TIME", "START_ANSWER_TIME", "END_ANSWER_TIME"]),
  },
};
</script>

<style lang="scss">
body {
  margin: 0 auto;
  max-width: 500px;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  position: relative;
  min-height: 100vh;
}

nav {
  padding: 30px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
}

nav a.router-link-exact-active {
  color: #42b983;
}
</style>
